package com.xcity.game.employee.config.impl;

import java.util.List;

import com.xcity.db.entity.Employee;
import com.xcity.game.employee.config.AbstractConfigure;
import com.xcity.game.employee.config.Configure;
import com.xcity.game.skill.SkillUtils;
import com.xcity.game.skill.template.SkillTemplate;
import com.xcity.game.skill.v2.DefaultSkillV2;

import naga.x.common.Interval;

/**
 * 员工技能产出配置
 * @author yang.li
 *
 */
@Deprecated
public class EmployeeSkillConfigure extends AbstractConfigure {

//	protected Random random;
//	protected Map<EmployeeQuality, List<Configuration>> activeSkillsConfigs = new EnumMap<EmployeeQuality, List<Configuration>>(EmployeeQuality.class);
//	protected Map<EmployeeQuality, List<Configuration>> passiveSkillsConfigs = new EnumMap<EmployeeQuality, List<Configuration>>(EmployeeQuality.class);
	
	protected static class Configuration implements Interval {
		protected SkillTemplate template;
		protected int weightFrom, weightTo;
		protected Configuration(SkillTemplate template, int weightFrom, int weightTo) {
			this.template = template;
			this.weightFrom = weightFrom;
			this.weightTo = weightTo;
		}
		@Override
		public int getMinVal() {
			return weightFrom;
		}
		@Override
		public int getMaxVal() {
			return weightTo;
		}
	}
	
	public EmployeeSkillConfigure(Configure parent) {
		super(parent);
//		random = EmployeeService.RND;
	}
	
	@Override
	public EmployeeSkillConfigure configure() {
//		List<EmployeeSkillProduceTemplate> templates = App.getApp().getServiceManager().get(TemplateService.class).getTemplatesList(EmployeeSkillProduceTemplate.class);
//		for (int i = 0, size = templates.size(); i < size; i++) {
//			EmployeeSkillProduceTemplate template = templates.get(i);
//			SkillTemplate skillTemplate = App.getApp().getServiceManager().get(TemplateService.class).get(SkillTemplate.class, template.getId());
//			Map<EmployeeQuality, List<Configuration>> configs = skillTemplate.getType() == SkillTemplate.TYPE_ACTIVE ? this.activeSkillsConfigs : this.passiveSkillsConfigs;
//			int[] weights = template.getWeights();
//			for (int j = 0, len = weights.length; j < len; j++) {
//				if (weights[j] > 0) {
//					EmployeeQuality key = EmployeeQuality.of(j);
//					List<Configuration> list = configs.get(key);
//					int weightFrom = 0;
//					if (list == null) {
//						list = new ArrayList<Configuration>();
//						configs.put(key, list);
//					} else {
//						weightFrom = list.get(list.size() - 1).getMaxVal();
//					}
//					int weightTo = weightFrom + weights[j];
//					list.add(new Configuration(skillTemplate, weightFrom, weightTo));
//				}
//			}
//		}
		return this;
	}
	
	public DefaultSkillV2 makeActiveSkill(Employee employee) {
		return SkillUtils.createActiveSkill(employee);
	}
	
	public List<DefaultSkillV2> makePassiveSkills(Employee employee) {
		return SkillUtils.createPassiveSkills(employee);
	}
	
//	private EmployeeSkill makeSkill(Employee employee, byte type) {
//		SkillTemplate template;
//		if (type == SkillTemplate.TYPE_ACTIVE
//				&& employee.getTemplate().getActiveSkillId() != 0
//				&& (template = App.getApp().getServiceManager().get(TemplateService.class).get(SkillTemplate.class, employee.getTemplate().getActiveSkillId())) != null) {
//			return new EmployeeSkill(template);
//		}
//		Map<EmployeeQuality, List<Configuration>> configs = type == SkillTemplate.TYPE_ACTIVE ? activeSkillsConfigs : passiveSkillsConfigs;
//		List<Configuration> list = configs.get(employee.getTemplate().getQuality());
//		if (list == null || list.isEmpty()) {
//			return null;
//		}
//		int weight = random.nextInt(list.get(list.size() - 1).getMaxVal());
//		Configuration found = CommonUtils.findInterval(list, weight);
//		return new EmployeeSkill(found.template);
//	}
	
}
